﻿using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Common;
using Medicalsystem.MCP.FormDesigner.Interface;

namespace Medicalsystem.MCP.FormDesigner.Property
{
    /// <summary>
    /// 继承 ICtrlUI 接口控件与属性编辑器交互
    /// </summary>
    public class GetCtrlUIProperty : GetCtrlProperty
    {
        /// <summary>
        /// 可视控件属性基类
        /// </summary>
        /// <param name="ctrlUI"></param>
        public GetCtrlUIProperty(System.Windows.Forms.Control ctrlUI) : base(ctrlUI) { }

        #region 布局

        /// <summary>
        /// 宽度
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("宽度")]
        [Description("控件宽度")]
        public int Width
        {
            get { return this._control.Width; }
            set
            {
                OnSetPropertyBatch(this, "Width", value);
                (_control as ICtrlBase).Model.ModelForm.Refresh();
            }
        }

        /// <summary>
        /// 高度
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("高度")]
        [Description("控件高度")]
        public int Height
        {
            get { return this._control.Height; }
            set
            {
                OnSetPropertyBatch(this, "Height", value);
                (_control as ICtrlBase).Model.ModelForm.Refresh();
            }
        }

        /// <summary>
        /// 上边距
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("上边距")]
        [Description("控件距容器顶部距离")]
        public int Top
        {
            get
            {
                return this._control.Top;
            }
            set
            {
                OnSetPropertyBatch(this, "Top", value);
                (_control as ICtrlBase).Model.ModelForm.Refresh();
            }
        }

        /// <summary>
        /// 左边距
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("左边距")]
        [Description("控件距容器左边距离")]
        public int Left
        {
            get
            {
                return this._control.Left;
            }
            set
            {
                OnSetPropertyBatch(this, "Left", value);
                (_control as ICtrlBase).Model.ModelForm.Refresh();
            }
        }

        /// <summary>
        /// 指定控件如何锚定到其容器的边缘
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("控件锚")]
        [Description("定义某个控件绑定到的容器的边缘")]
        public AnchorStyles Anchor
        {
            get
            {
                return this._control.Anchor;
            }
            set
            {
                OnSetPropertyBatch(this, "Anchor", value);
            }
        }

        /// <summary>
        /// 定义要绑定到容器的控件边框
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("Dock")]
        [Description("定义要绑定到容器的控件边框")]
        public DockStyle Dock
        {
            get
            {
                return this._control.Dock;
            }
            set
            {
                OnSetPropertyBatch(this, "Dock", value);
                (_control as ICtrlBase).Model.ModelForm.Refresh();
            }
        }

        #endregion 布局

        #region 外观

        /// <summary>
        /// 背景颜色
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("背景颜色")]
        [Description("背景颜色")]
        public virtual Color BackColor
        {
            get
            {
                return this._control.BackColor;
            }
            set
            {
                OnSetPropertyBatch(this, "BackColor", value);
            }
        }

        /// <summary>
        /// 前景颜色
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("前景颜色")]
        [Description("前景颜色")]
        public virtual Color ForeColor
        {
            get
            {
                return this._control.ForeColor;
            }
            set
            {
                OnSetPropertyBatch(this, "ForeColor", value);
            }
        }

        /// <summary>
        /// 文本
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("文本")]
        [Description("控件文本")]
        [EditorAttribute(typeof(ContentEditorDropDown), typeof(System.Drawing.Design.UITypeEditor))]
        public virtual string ShowText
        {
            get
            {
                return ((ICtrlUI)_control).ShowText;
            }
            set
            {
                OnSetPropertyBatch(this, "ShowText", value);
            }
        }

        /// <summary>
        /// 字体
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("字体")]
        [Description("字体")]
        public virtual Font Font
        {
            get
            {
                return this._control.Font;
            }
            set
            {
                OnSetPropertyBatch(this, "Font", value);
            }
        }

        /// <summary>
        /// 边框样式
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("边框样式")]
        [Description("控件边框样式")]
        public virtual EBorderStyle BorderStyleZ
        {
            get { return (this._control as ICtrlUI).BorderStyleZ; }
            set
            {
                OnSetPropertyBatch(this, "BorderStyleZ", value);
            }
        }

        #endregion 外观

        #region 行为

        /// <summary>
        /// Tab 键顺序
        /// </summary>
        [CategoryAttribute("行为")]
        [ShowChinese("Tab键顺序")]
        [Description("控件在容器中的 Tab 键顺序")]
        public int TabIndex
        {
            get { return this._control.TabIndex; }
            set
            {
                this._control.TabIndex = value;
            }
        }

        /// <summary>
        /// 显示
        /// </summary>
        [CategoryAttribute("行为")]
        [ShowChinese("显示")]
        [Description("确定该控件时可见的还是隐藏的")]
        public bool VisibleZ
        {
            get { return (this._control as ICtrlUI).VisibleZ; }
            set
            {
                OnSetPropertyBatch(this, "VisibleZ", value);
            }
        }

        #endregion 行为

        /// <summary>
        /// 设置控件属性
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public override void SetProperty(string propertyName, object value)
        {
            switch (propertyName.ToLower())
            {
                case "width":
                    this._control.Width = (int)value;
                    break;

                case "height":
                    this._control.Height = (int)value;
                    break;

                case "top":
                    this._control.Top = (int)value;
                    break;

                case "left":
                    this._control.Left = (int)value;
                    break;

                case "anchor":
                    this._control.Anchor = (AnchorStyles)value;
                    break;

                case "dock":
                    this._control.Dock = (DockStyle)value;
                    break;

                case "backcolor":
                    this._control.BackColor = (Color)value;
                    break;

                case "forecolor":
                    this._control.ForeColor = (Color)value;
                    break;

                case "showtext":
                    (this._control as ICtrlUI).ShowText = value.ToString();
                    break;

                case "font":
                    this._control.Font = (Font)value;
                    break;

                case "visiblez":
                    (this._control as ICtrlUI).VisibleZ = (bool)value;
                    break;

                case "borderstylez":
                    (this._control as ICtrlUI).BorderStyleZ = (EBorderStyle)value;
                    break;
                default:
                    base.SetProperty(propertyName, value);
                    break;
            }
        }
    }
}